﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SWDataDB.BLL
{
    public class PublicClass
    {
        public PublicClass(){}

        #region ===时间操作===

        //得到年year
        public static string GetTimeYear(string strRq)
        {
            if (strRq == "")
                return strRq;

            string strOutPut = "";
            strOutPut = strRq.Substring(0, 4);
            return strOutPut;
        }

        //得到月mon
        public static string GetTimeMon(string strRq)
        {
            if (strRq == "")
                return strRq;

            string strOutPut = "";
            strOutPut = strRq.Substring(5, 2);

            return strOutPut;
        }

        //得到日
        public static string GetTimeDay(string strRq)
        {
            if (strRq == "")
                return strRq;

            string strOutPut = "";
            strOutPut = strRq.Substring(8, 2);

            return strOutPut;
        }

        //格式化年月日_“-”
        public static string MergeDate(string year,string mon,string day)
        {
            string strOutPut = "";

            if (year == "" || mon == "" ||day == "")
                return strOutPut;

            strOutPut = year + "-";
            strOutPut += mon + "-";
            strOutPut += day;

            return strOutPut;
        }

        //格式化年月日_中文
        public static string FormatRq_C(string strRq)
        {
            if (strRq == "")
                return strRq;

            string strOutPut = "";
            int intIndex1 = 0;
            int intIndex2 = 0;
            strOutPut = strRq.Substring(0, 4) + "年";
            intIndex1 = strRq.IndexOf('-', 5);
            strOutPut += strRq.Substring(5, intIndex1 - 5) + "月";
            intIndex2 = strRq.IndexOf(' ', 0);
            strOutPut += strRq.Substring(intIndex1 + 1, intIndex2 - intIndex1) + "日";
            return strOutPut;
        }

        //格式化年月日_中文带时间
        public static string FormatRq_Ct(string strRq)
        {
            if (strRq == "")
                return strRq;

            string strOutPut = "";
            int intIndex1 = 0;
            int intIndex2 = 0;
            strOutPut = strRq.Substring(0, 4) + "年";
            intIndex1 = strRq.IndexOf('-', 5);
            strOutPut += strRq.Substring(5, intIndex1 - 5) + "月";
            intIndex2 = strRq.IndexOf(' ', 0);
            strOutPut += strRq.Substring(intIndex1 + 1, intIndex2 - intIndex1 - 1) + "日";
            intIndex1 = strRq.IndexOf(':', 0);
            strOutPut += strRq.Substring(intIndex2 + 1, intIndex1 - intIndex2 - 1) + "时";
            return strOutPut;
        }

        //格式化年月日
        public static string FormatRq_E(string strRq)
        {
            if (strRq == "")
                return strRq;

            string strOutPut = "";
            strOutPut = strRq.Replace("年", "-");
            strOutPut = strOutPut.Replace("月", "-");
            strOutPut = strOutPut.Replace("日", "");
            return strOutPut;

        }

        #endregion

        #region ===经纬度操作===
        //得到度分秒,DMS[0]-->度；DMS[1]-->分；DMS[2]-->秒
        public static int[] GetPosDMS(int pos)
        {
            int[]DMS = new int[3];

            DMS[0] = pos / 10000;
            DMS[1] = (pos % 10000) / 100;
            DMS[2] = (pos % 100);

            return DMS;
        }

        //通过度分秒合并为DMS格式
        public static int MergeDMS(int D,int M,int S)
        {
            int DMS;

            DMS = S + M * 100 + D * 10000;

            return DMS;
        }

        //DD.MS格式->DDDMMSS
        public static int DBFtoDMS(double DBF)
        {
            int DMS;

            int sumM = (int)(DBF * 3600);

            int D = (int)(sumM / 3600);
            int M = (int)((sumM - D * 3600) / 60);
            int S = (int)((sumM - D * 3600) % 60);

            DMS = MergeDMS(D, M, S);

            return DMS;
        }
        //DDDMMSS-->DD.MS格式
        public static double DMStoDBF(int DMS)
        {
            double dbf;

            int[] DDDMMSS = new int[3];
            DDDMMSS = GetPosDMS(DMS);

            dbf = (DDDMMSS[0] * 3600 + DDDMMSS[1] * 60 + DDDMMSS[2]) / 3600;

            return dbf;
        }

        #endregion
    }
}
